package com.mohoo.weixin.servlet;

import java.io.IOException;  
import java.io.InputStream;  
  
/** 
   *���յ������󴮵ľ����ʽ���£� 
   * GET /aaa.htm HTTP/1.1 
   * Host: 127.0.0.1:8080 
   * Connection: keep-alive 
   * User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11 
   * Accept: text/html,application/xhtml+xml,application/xml;q=0.9,q=0.8 
   * Accept-Encoding: gzip,deflate,sdch 
   * Accept-Language: zh-CN,zh;q=0.8 
   * Accept-Charset: GBK,utf-8;q=0.7,*;q=0.3 
   *  
   * @author zhaozheng 
   * 
 */  
public class Request {  
  
    private InputStream input;  
    private String uri;  
    private String myxml;
    public Request(InputStream input) {  
        this.input = input;  
    }  
      
    public void parser() {  
        StringBuffer request = new StringBuffer();  

        byte[] buffer = new byte[2048];  
        int i = 0;  
          
        try {  
            i = input.read(buffer);  
        } catch (IOException e) {  
            e.printStackTrace();  
            i = -1;  
        }  
          
        for(int k = 0; k < i; k++) {  
            request.append((char)buffer[k]);  
        }  
        System.out.println("request="+request.toString());          //接收到的request信息
        myxml=  parserUriXml(request.toString());
 
          System.out.println("request中提取到的xml:----------------------"+myxml);
          
    }  
      
 
    private String parserUriXml(String requestData) {  
        int index1, index2;  
//        System.out.println("***********"+requestData+"************");
        index1 = requestData.indexOf("<xml>"); 
        System.out.println(index1);
        if(index1 != -1) {  
        	{//System.out.println("index1!=-1--------------------");
            index2 = requestData.indexOf("</xml>");  }
            if(index2 > index1) {  
            	//System.out.println("index1!=-1--------------------");
            	//System.out.println("index1="+index1+"   index2-----="+index2);
                return requestData.substring(index1, index2+6);  
            }  
        }  
        	return "这个工具这次没有传过来内容";
          
         
    }
    public String getMyXml() {  
        return myxml;  
    } 
    public String getUri() {  
        return uri;  
    }  
}  